package com.sleep.psy.external_server.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

;

@Configuration
@EnableSwagger2
public class Swagger2Config {

    @Bean
    public Docket docket() {
        //添加head参数start
        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
        tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
        pars.add(tokenPar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .ignoredParameterTypes(UserInfoRes.class, UserPermissionInfo.class) //隐藏接口中的用户信息参数
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.sleep.psy.external_server"))
                .paths(PathSelectors.any())
                .build()
//                .pathMapping("/api/idi-user")  // 所有接口统一增加/api/idi-user前缀（网关访问路径）
                .globalOperationParameters(pars);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("external_server服务项目API文档")
                .description("心理研究院服务接口")
                .version("v1")
                .termsOfServiceUrl("No terms of service")
                .build();
    }

}